package org.jeecg.modules.demo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.JWT;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.logging.impl.WeakHashtable;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.pandian.entity.Pandian;
import org.jeecg.modules.demo.pandian.entity.Pandiandetail;
import org.jeecg.modules.demo.pandian.mapper.PandiandetailMapper;
import org.jeecg.modules.demo.pandian.service.IPandianService;
import org.jeecg.modules.demo.pandian.service.IPandiandetailService;
import org.jeecg.modules.online.cgform.util.CgformUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description
 * @Date 2020/9/28 0028 14:33
 * @Created by 郭振兴
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/databsecontroller")
@Api(tags="高级查询")
@Slf4j
public class dabasecontroller {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    RedisUtil redisUtil;
    @Value("${spring.subject}")
    private String subject;
    @Autowired
    private IPandiandetailService pandiandetailService;
    @Autowired
    private IPandianService pandianService;
    @Autowired
    private PandiandetailMapper pandiandetailMapper;


    @RequestMapping(value="/getfield",produces = { "application/json;charset=UTF-8" },method = RequestMethod.POST)
    @ApiOperation(value = "高级查询当前字段列表", notes = "高级查询当前字段列表")
    @ResponseBody
    public ResponseEntity<?> getfield(
            @ApiParam(value = "body", required = false) @RequestBody JSONObject configbody
    ){
        JSONObject object1 =  new JSONObject();
        try {
            String sql="SELECT\n" +
                    "\t*\n" +
                    "FROM\n" +
                    "\tonl_cgform_field\n" +
                    "WHERE\n" +
                    "\tcgform_head_id IN (\n" +
                    "\t\tSELECT\n" +
                    "\t\t\tid\n" +
                    "\t\tFROM\n" +
                    "\t\t\tonl_cgform_head\n" +
                    "\t\tWHERE\n" +
                    "\t\t\ttable_name = '"+configbody.getString("databasename")+"'\n" +
                    "\t)";
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
        e.printStackTrace();
        object1.put("code", "-1");
        object1.put("msg", "系统错误");
        return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


    }
    }

    @RequestMapping(value="/updatebasepart",produces = { "application/json;charset=UTF-8" },method = RequestMethod.POST)
    @ApiOperation(value = "更新basepartbom状态", notes = "更新basepartbom状态")
    @ResponseBody
    public ResponseEntity<?> updatebasepart(
            @ApiParam(value = "body", required = false) @RequestBody JSONObject configbody
    ){
        JSONObject object1 =  new JSONObject();
        try {
            String sql="update basepart set iscbom='1' where id='"+configbody.getString("id")+"'";
            jdbcTemplate.update(sql);

            object1.put("code", "0000");
            object1.put("msg", "BOM状态更新成功");

            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //打印公用对象
    @AutoLog(value = "打印")
    @ApiOperation(value="打印", notes="打印")
    @GetMapping(value = "/printobject")
    public ResponseEntity<?> printobject(
            @RequestParam(name="mystring", defaultValue="") String mystring,
            @RequestParam(name = "tablename", defaultValue = "") String tablename
    ){
        JSONObject object1 =  new JSONObject();
        tablename="basepart";
        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
              mystring="1360360134022324226,1360360255925575681,1360360860459069441";
        } else {

            System.out.println(sql);
        }
        sql = "select * from " + tablename + " where id in (" + mystring + ")";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //通过id查询产品明细表
    @AutoLog(value = "产品明细主表通过id查询")
    @ApiOperation(value="产品明细主表通过id查询", notes="产品明细主表通过id查询")
    @GetMapping(value = "/searchprodcutdetail")
    public ResponseEntity<?> searchprodcutdetail(
            @RequestParam(name="id", defaultValue="") String id
    ){
        JSONObject object1 =  new JSONObject();

        try {
            String sql="select * from productdetail where partid ='"+id+"'";
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //cboot判读设备目录相应的接口
    @AutoLog(value = "判断工艺目录关系表是否存在")
    @ApiOperation(value="判断工艺目录关系表是否存在", notes="判断工艺目录关系表是否存在")
    @GetMapping(value = "/checkprogrammequip")
    public ResponseEntity<?> checkprogrammequip(

            @RequestParam(name="pdh", defaultValue="") String pdh,
            @RequestParam(name="pnumber", defaultValue="") String pnumber
    ){
        JSONObject object1 =  new JSONObject();

        try {
            String sql="select * from procrelatioship where  pdh ='"+pdh+"' and pnumber='"+pnumber+"'" ;
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            if (object1.getJSONArray("data").size()>0){
                object1.put("code", "-1");
                object1.put("msg", "数据已经存在");
            }
            else {
                object1.put("code", "0000");
                object1.put("msg", "可以添加新数据");
                object1.put("data", list);
            }
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //cboot判读物料是否存在的接口

    @AutoLog(value = "判断物料是否存在")
    @ApiOperation(value="判断物料是否存在", notes="判断物料是否存在")
    @GetMapping(value = "/checkpart")
    public ResponseEntity<?> checkpart(

            @RequestParam(name="gydh", defaultValue="") String gydh,
            @RequestParam(name="gxbm", defaultValue="") String gxbm
    ){
        JSONObject object1 =  new JSONObject();

        try {
            String sql="select * from gxwl where  gydh ='"+gydh+"' and gxbm='"+gxbm+"'" ;
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            if (object1.getJSONArray("data").size()>0){
                object1.put("code", "-1");
                object1.put("msg", "数据已经存在");
            }
            else {
                object1.put("code", "0000");
                object1.put("msg", "可以添加新数据");
                object1.put("data", list);
            }
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }



    //获取当前供应链系统设置参数
    @AutoLog(value = "获取供应链参数")
    @ApiOperation(value="获取供应链参数", notes="获取供应链参数")
    @GetMapping(value = "/getsystemp")
    public ResponseEntity<?> getsystemp(

            @RequestParam(name="mokuai", defaultValue="") String mokuai

    ){
        JSONObject object1 =  new JSONObject();

        try {
            String sql="select * from xsettings where   mokuai ='"+ mokuai+"' " ;
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            if (object1.getJSONArray("data").size()==0){
                object1.put("code", "-1");
                object1.put("msg", "系统配置不存在！");
            }
            else {
                object1.put("code", "0000");
                object1.put("msg", "系统配置获取成功！");
                object1.put("data", list);
            }
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

    @AutoLog(value = "打印销售订单接口")
    @ApiOperation(value="打印销售订单接口", notes="打印")
    @GetMapping(value = "/printobject1")
    public ResponseEntity<?> printobject1(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="1375781659824713729";
        } else {

            System.out.println(sql);
        }
        sql = "\n" +
                "SELECT\n" +
                "\t*\n" +
                "FROM\n" +
                "\torder_maintain\n" +
                "LEFT JOIN orderdetail ON order_maintain.id = orderdetail.sid\n" +
                "WHERE\n" +
                "\torder_maintain.id = '"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            object1.put("data", list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //打印合格证二维码
    @AutoLog(value = "打印合格证二维码")
    @ApiOperation(value="打印合格证二维码", notes="打印")
    @GetMapping(value = "/printhegezheng")
    public ResponseEntity<?> printhegezheng(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();
        String sql="";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="ca74755e-7829-74e2-1898-b8e993a76370";
        } else {

            System.out.println(sql);
        }
        sql = "select * from packageplan where id='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            JSONArray data =object2.getJSONArray("data");


            return new ResponseEntity<>(object2, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
 //入库单打印
 @AutoLog(value = "入库单明细打印")
 @ApiOperation(value="入库单明细打印", notes="打印")
 @GetMapping(value = "/printrukudetail")
 public ResponseEntity<?> printrukudetail(
         @RequestParam(name="mystring", defaultValue="") String mystring

 ){
     JSONObject object1 =  new JSONObject();
     JSONObject object2 =  new JSONObject();

     String sql = "";
     if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
         mystring="0436860c-4752-2ec0-e4d3-801e18830c00";
     } else {

         System.out.println(sql);
     }
     sql = "select * from procurement_warehousing_child where procurement_warehousing_id='"+mystring+"'";
     try {
         System.out.println(sql);
         List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
         object2.put("data",list);
         object1.put("code", "0000");
         object1.put("msg", "系统获取成功");

         object1.put("data",list);
         return new ResponseEntity<>(object1, HttpStatus.OK);
     }
     catch (Exception e) {
         e.printStackTrace();
         object1.put("code", "-1");
         object1.put("msg", "系统错误");
         return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


     }
 }
 @AutoLog(value = "入库单打印")
 @ApiOperation(value="入库单打印", notes="打印")
 @GetMapping(value = "/printrkudan")
 public ResponseEntity<?> printrkudan(
         @RequestParam(name="mystring", defaultValue="") String mystring

 ){
     JSONObject object1 =  new JSONObject();
     JSONObject object2 =  new JSONObject();

     String sql = "";
     if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
         mystring="0436860c-4752-2ec0-e4d3-801e18830c00";
     } else {

         System.out.println(sql);
     }
     sql = "select * from procurement_warehousing where id='"+mystring+"'";
     try {
         System.out.println(sql);
         List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
         object2.put("data",list);
         object1.put("code", "0000");
         object1.put("msg", "系统获取成功");
         JSONArray data =object2.getJSONArray("data");
         object1.put("create_by",data.getJSONObject(0).getString("create_by"));
         object1.put("create_time",data.getJSONObject(0).getString("create_time"));
         object1.put("sys_org_code",data.getJSONObject(0).getString("sys_org_code"));
         object1.put("document_num",data.getJSONObject(0).getString("document_num"));
         object1.put("warehouse_name",data.getJSONObject(0).getString("warehouse_name"));
         object1.put("supplier",data.getJSONObject(0).getString("supplier"));
         object1.put("cangwei",data.getJSONObject(0).getString("cangwei"));
         object1.put("rukuleixing",data.getJSONObject(0).getString("rukuleixing"));
         object1.put("data",list);
         return new ResponseEntity<>(object1, HttpStatus.OK);
     }
     catch (Exception e) {
         e.printStackTrace();
         object1.put("code", "-1");
         object1.put("msg", "系统错误");
         return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


     }
 }
 //领料单
 @AutoLog(value = "领料单打印")
 @ApiOperation(value="领料单打印", notes="打印")
 @GetMapping(value = "/printlingliao")
 public ResponseEntity<?> printlingliao(
         @RequestParam(name="mystring", defaultValue="") String mystring

 ){
     JSONObject object1 =  new JSONObject();
     JSONObject object2 =  new JSONObject();

     String sql = "";
     if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
         mystring="0393a761-c941-045b-6c74-4ad98638a825";
     } else {

         System.out.println(sql);
     }
     sql = "select * from lingliao where id='"+mystring+"'";
     try {
         System.out.println(sql);
         List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
         object2.put("data",list);
         object1.put("code", "0000");
         object1.put("msg", "系统获取成功");
         JSONArray data =object2.getJSONArray("data");
         object1.put("create_by",data.getJSONObject(0).getString("create_by"));
         object1.put("create_time",data.getJSONObject(0).getString("create_time"));
         object1.put("sys_org_code",data.getJSONObject(0).getString("sys_org_code"));
         object1.put("fnumber",data.getJSONObject(0).getString("fnumber"));
         object1.put("fname",data.getJSONObject(0).getString("fname"));
         object1.put("stock",data.getJSONObject(0).getString("stock"));
         object1.put("gongxu",data.getJSONObject(0).getString("gongxu"));
         object1.put("cangwei",data.getJSONObject(0).getString("cangwei"));
         object1.put("chukuleixing",data.getJSONObject(0).getString("chukuleixing"));
         object1.put("data",list);
         return new ResponseEntity<>(object1, HttpStatus.OK);
     }
     catch (Exception e) {
         e.printStackTrace();
         object1.put("code", "-1");
         object1.put("msg", "系统错误");
         return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


     }
 }
    @AutoLog(value = "领料单打印")
    @ApiOperation(value="领料单打印", notes="打印")
    @GetMapping(value = "/printlingliaodetail")
    public ResponseEntity<?> printlingliaodetail(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="0393a761-c941-045b-6c74-4ad98638a825";
        } else {

            System.out.println(sql);
        }
        sql = "select * from lingliaodetail where lid='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
//
    @AutoLog(value = "计划单打印接口")
    @ApiOperation(value="计划单打印接口", notes="打印")
    @GetMapping(value = "/printobject2")
    public ResponseEntity<?> printobject2(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="1376002493231218689";
        } else {

            System.out.println(sql);
        }
        sql = "select * from mplan where id='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");
            JSONArray data =object2.getJSONArray("data");
            object1.put("fnumber",data.getJSONObject(0).getString("fnumber"));
            object1.put("fname",data.getJSONObject(0).getString("fname"));
            object1.put("sday",data.getJSONObject(0).getString("sday"));
            object1.put("endday",data.getJSONObject(0).getString("endday"));
            object1.put("endday",data.getJSONObject(0).getString("endday"));
            sql="select * from mplandetail where mid='"+mystring+"'";
             list =  jdbcTemplate.queryForList(sql);
            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    // 工单二维码打印
    @AutoLog(value = "工单二维码打印")
    @ApiOperation(value="工单二维码打印", notes="打印")
    @GetMapping(value = "/printobject5")
    public ResponseEntity<?> printobject5(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="ce9cda24eba4857738866da86030fe81";
        } else {

            System.out.println(sql);
        }
        String tablename="sporder";
        sql = "select * from " + tablename + " where id in (" + mystring + ")";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //计划主表打印
    @AutoLog(value = "计划主表打印接口")
    @ApiOperation(value="计划主表打印接口", notes="打印")
    @GetMapping(value = "/printobject3")
    public ResponseEntity<?> printobject3(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="1376002493231218689";
        } else {

            System.out.println(sql);
        }
        sql = "select * from mplan where id='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取销售模块辅助计量单位和第三量单位
    @AutoLog(value = "获取销售模块计量单位信息")
    @ApiOperation(value="获取销售模块计量单位信息", notes="打印")
    @GetMapping(value = "/getunitinformation")
    public ResponseEntity<?> getunitinformation(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select base_unit,weight_unit,junit,sale_unit,sweightunit,saleunit from basepart where part_code='"+mystring+"'";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            JSONArray data =object2.getJSONArray("data");
//            基础计量单位
            String  base_unit=data.getJSONObject(0).getString("base_unit");
            String  weight_unit=data.getJSONObject(0).getString("weight_unit");
            String  junit=data.getJSONObject(0).getString("junit");
            String  sale_unit=data.getJSONObject(0).getString("sale_unit");
            String  sweightunit=data.getJSONObject(0).getString("sweightunit");
            String  saleunit=data.getJSONObject(0).getString("saleunit");
            System.out.println(saleunit);
            if((sale_unit== null || sale_unit.length() == 0)||(sweightunit== null || sweightunit.length() == 0)||(saleunit== null || saleunit.length() == 0)){
                object1.put("base_unit",base_unit);
                object1.put("weight_unit",weight_unit);
                object1.put("junit",junit);
            }
            else {
                object1.put("base_unit",sale_unit);
                object1.put("weight_unit",sweightunit);
                object1.put("junit",saleunit);
            }
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
//    获取主计量单位与辅助计量单位和第三量单位整体换算关系（销售使用）
@AutoLog(value = "获取计量单位辅助关系")
@ApiOperation(value="获取计量单位辅助关系", notes="打印")
@GetMapping(value = "/gethuansuan")
public ResponseEntity<?> gethuansuan(
        @RequestParam(name="mystring", defaultValue="") String mystring

){
    JSONObject object1 =  new JSONObject();
    JSONObject object2 =  new JSONObject();

    String sql = "";

    sql = "select * from munit where fname='"+mystring+"'";
    try {
        System.out.println(sql);
        List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
        object2.put("data",list);
        object1.put("code", "0000");
        object1.put("msg", "系统获取成功");
        JSONArray data =object2.getJSONArray("data");
        String myid=data.getJSONObject(0).getString("id");
        sql="select * from huansuan where mid='"+myid+"'";
        list =  jdbcTemplate.queryForList(sql);
        object1.put("data", list);
        return new ResponseEntity<>(object1, HttpStatus.OK);
    }
    catch (Exception e) {
        e.printStackTrace();
        object1.put("code", "-1");
        object1.put("msg", "系统错误");
        return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


    }
}
  //获取生产计划和计划明细
  @AutoLog(value = "获取生产计划和计划明细")
  @ApiOperation(value="获取生产计划和计划明细", notes="打印")
  @GetMapping(value = "/getplan")
  public ResponseEntity<?> getplan(
          @RequestParam(name="mystring", defaultValue="") String mystring

  ){
      JSONObject object1 =  new JSONObject();
      JSONObject object2 =  new JSONObject();

      String sql = "";

      sql = "select * from mplan where id='"+mystring+"'";
      try {
          System.out.println(sql);
          List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
          String sql1="select * from mplandetail where mid='"+mystring+"'";
          System.out.println(sql1);
          List<Map<String, Object>> list1 =  jdbcTemplate.queryForList(sql1);
          object1.put("data",list);
          object1.put("planlist",list1);
          object1.put("code", "0000");
          object1.put("msg", "系统获取成功");



          return new ResponseEntity<>(object1, HttpStatus.OK);
      }
      catch (Exception e) {
          e.printStackTrace();
          object1.put("code", "-1");
          object1.put("msg", "系统错误");
          return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


      }
  }
    //获取工艺与工艺明细
    @AutoLog(value = "获取工艺与工艺明细")
    @ApiOperation(value="获取工艺与工艺明细", notes="打印")
    @GetMapping(value = "/getgongyi")
    public ResponseEntity<?> getgongyi(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from workmanship where wnumber='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            JSONArray  sdata=object2.getJSONArray("data");
            String wid=sdata.getJSONObject(0).getString("id");
            String sql1="select * from myproc where mainid='"+wid+"'";
            System.out.println(sql1);
            List<Map<String, Object>> list1 =  jdbcTemplate.queryForList(sql1);
            object1.put("data",list);
            object1.put("planlist",list1);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");



            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取未完工工单
    //获取用户当前未读消息
    @AutoLog(value = "获取用户当前未读消息")
    @ApiOperation(value="获取用户当前未读消息", notes="获取用户当前未读消息")

    @RequestMapping(value = "/getwdmessage", method = RequestMethod.GET)
    public ResponseEntity<?> getwdmessage(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql="select * from sys_announcement_send where user_id='"+mystring+"' and read_flag='0' ";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object1.put("data", list);
            object1.put("code", "0000");
            object1.put("msg", "操作成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
//
    @AutoLog(value = "获取未完工工单")
    @ApiOperation(value="获取未完工工单", notes="获取未完工工单")
    @GetMapping(value = "/getyygongdan")
    public ResponseEntity<?> getyygongdan(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from sporder where wgzt='未完工' and fnumber='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取工单信息及其工单成品信息
    @AutoLog(value = "获取工单信息及其工单成品信息")
    @ApiOperation(value="获取工单信息及其工单成品信息", notes="打印")
    @GetMapping(value = "/getmyorder")
    public ResponseEntity<?> getmyorder(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\t*\n" +
                "FROM\n" +
                "\tsporder s\n" +
                "LEFT JOIN gdcp g ON s.id = g.sporderid ";
        if (mystring != "" && mystring != null && mystring.compareTo("") != 0) {
            sql+=" and  LOCATE('"+mystring+"', s.fnumber) > 0";
        }
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //套打获取工单头信息，成品，工序，物料信息
    @AutoLog(value = "获取工单头信息")
    @ApiOperation(value="打印工单头信息", notes="打印")
    @GetMapping(value = "/getgongdanhead")
    public ResponseEntity<?> getgongdanhead(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="ce9cda24eba4857738866da86030fe81";
        } else {

            System.out.println(sql);
        }
        String tablename="sporder";
        sql = "select * from " + tablename + " where id='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
   //获取工单成功信息
   @AutoLog(value = "获取工单成品信息")
   @ApiOperation(value="获取工单成品信息", notes="打印")
   @GetMapping(value = "/getgongdancp")
   public ResponseEntity<?> getgongdancp(
           @RequestParam(name="mystring", defaultValue="") String mystring

   ){
       JSONObject object1 =  new JSONObject();
       JSONObject object2 =  new JSONObject();

       String sql = "";
       if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
           mystring="07e08074352aed07226f825a31ef5556";
       } else {

           System.out.println(sql);
       }
       String tablename="gdcp";
       sql = "select * from " + tablename + " where sporderid='"+mystring+"'";
       try {
           System.out.println(sql);
           List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
           object2.put("data",list);
           object1.put("code", "0000");
           object1.put("msg", "系统获取成功");

           object1.put("data",list);
           return new ResponseEntity<>(object1, HttpStatus.OK);
       }
       catch (Exception e) {
           e.printStackTrace();
           object1.put("code", "-1");
           object1.put("msg", "系统错误");
           return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


       }
   }
    //获取工序物料信息
    @AutoLog(value = "获取工单工序物料信息")
    @ApiOperation(value="获取工单工序物料信息", notes="打印")
    @GetMapping(value = "/getgxwuliao")
    public ResponseEntity<?> getgxwuliao(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="07e08074352aed07226f825a31ef5556";
        } else {

            System.out.println(sql);
        }
        String tablename="gxwuliao";
        sql = "select * from " + tablename + " where sporderid='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取工序成品信息
    @AutoLog(value = "获取工序成品信息")
    @ApiOperation(value="获取工序成品信息", notes="打印")
    @GetMapping(value = "/getgxcp")
    public ResponseEntity<?> getgxcp(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="07e08074352aed07226f825a31ef5556";
        } else {

            System.out.println(sql);
        }
        String tablename="gxcp";
        sql = "select * from " + tablename + " where sporderid='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "通过用户id获取角色")
    @ApiOperation(value="通过用户id获取角色", notes="通过用户id获取角色")
    @GetMapping(value = "/getuserrole")
    public ResponseEntity<?> getuserrole(
            @RequestParam(name="mystring", defaultValue="") String mystring,
            @RequestParam(name="mystring1", defaultValue="") String mystring1
    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql="select * from \n" +
                "(select r.role_name,u.id from sys_user u\n" +
                "left join sys_user_role t\n" +
                "on u.id=t.user_id \n" +
                "left join sys_role r\n" +
                "on t.role_id=r.id) m  where m.id='"+mystring+"'";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);


            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取工序信息
    @AutoLog(value = "获取工单工序信息")
    @ApiOperation(value="获取工单工序信息", notes="打印")
    @GetMapping(value = "/getgordergx")
    public ResponseEntity<?> getgordergx(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";
        if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
            mystring="07e08074352aed07226f825a31ef5556";
        } else {

            System.out.println(sql);
        }
        String tablename="gordergx";
        sql = "select * from " + tablename + " where kid='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "系统获取成功");

            object1.put("data",list);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //展开工单bom
    @AutoLog(value = "获取产品明细")
    @ApiOperation(value="获取产品明细", notes="打印")
    @GetMapping(value = "/getproductdetail")
    public ResponseEntity<?> getproductdetail(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from pdetail where partcode='"+mystring+"' and has_child=1";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            JSONArray productdata=object2.getJSONArray("data");
            if (productdata.size()==0){
                object1.put("data",list);
                object1.put("code", "-1");
                object1.put("msg", "BOM下没有物料!");
            }
            else {
                object1.put("data",list);
                object1.put("code", "0000");
                object1.put("msg", "数据获取成功");
                String pid=productdata.getJSONObject(0).getString("id");
                //获取bom下的数据
                String sql1 = "select * from pdetail where pid='"+pid+"' ";
                List<Map<String, Object>> list2 =  jdbcTemplate.queryForList(sql1);
                System.out.println(list2);
                object1.put("pid", pid);
                object1.put("bomlist", list2);
                JSONArray bomlist=object1.getJSONArray("bomlist");
                for (int i=0;i<bomlist.size();i++){
                    String pid1=bomlist.getJSONObject(i).getString("id");
                    System.out.println(pid1);
                    List<Map<String, Object>> list3 = getmylist(pid1);
                    System.out.println(list3);
                    list2.addAll(list3);

                }
                object1.put("bomlist", list2);
            }
            //展开第一层bom内容




            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    List getmylist(String pid9) throws Exception {
        String sql2 = "select * from pdetail where pid='"+pid9+"' ";
        List<Map<String, Object>> list5 =  jdbcTemplate.queryForList(sql2);
        System.out.println(list5);

        return  list5;
    }
    //获取物料详情接口
    @AutoLog(value = "获取物料详情")
    @ApiOperation(value="获取物料详情", notes="打印")
    @GetMapping(value = "/getmybasepart")
    public ResponseEntity<?> getmybasepart(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from basepart where part_code='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

                object1.put("data",list);
                object1.put("code", "0000");
                object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    /**
     * 通过 ruleCode 执行自定义填值规则
     *
     * @param ruleCode 要执行的填值规则编码
     * @param formData 表单数据，可根据表单数据的不同生成不同的填值结果
     * @return 运行后的结果
     */
    @AutoLog(value = "获取编号")
    @ApiOperation(value="获取编号", notes="打印")
    @GetMapping("/executeRuleByCode1/{ruleCode}")
    public Result executeByRuleCode1(@PathVariable("ruleCode") String ruleCode, @RequestBody JSONObject formData) {
        Object result = FillRuleUtil.executeRule(ruleCode,formData);
        return Result.ok(result);
    }
    //获取当前部门对应的工序名字
    @AutoLog(value = "获取工序名字")
    @ApiOperation(value="获取工序名", notes="查询工序")
    @GetMapping(value = "/getdepartname")
    public ResponseEntity<?> getdepartname(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from sys_depart  where org_code='"+mystring+"'";
        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //更新采购订单剩余量
    @AutoLog(value = "更新采购订单剩余量")
    @ApiOperation(value="更新采购订单剩余量", notes="更新采购订单剩余量")
    @GetMapping(value = "/updatepurchaseorderset")
    public ResponseEntity<?> updatepurchaseorderset(
            @RequestParam(name="fnumber", defaultValue="") String fnumber,
            @RequestParam(name="num", defaultValue="") int num
    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "update caigouorderdetail  set rnum=ifnull(rnum,0)+"+num+" where fnumber='"+fnumber+"'";

        try {
            jdbcTemplate.execute(sql);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //查询工单流转卡
    @AutoLog(value = "检查流转卡")
    @ApiOperation(value="检查流转卡", notes="检查流转卡")
    @GetMapping(value = "/checklzk")
    public ResponseEntity<?> checklzk(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from sporder where fnumber='"+mystring+"'";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取当前完工量
    @AutoLog(value = "获取当前完工量")
    @ApiOperation(value="获取当前完工量", notes="检查流转卡")
    @GetMapping(value = "/getwangong")
    public ResponseEntity<?> getwangong(
            @RequestParam(name="mystring", defaultValue="") String mystring,
            @RequestParam(name="mystring1", defaultValue="") String mystring1,
            @RequestParam(name="mystring2", defaultValue="") String mystring2


    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tIFNULL(sum(CAST(num AS SIGNED)), 0) AS mysum\n" +
                "FROM\n" +
                "\tjobmat\n" +
                "WHERE\n" +

                " fname = '"+mystring+"'\n" +
                "AND partcode = '"+mystring1+"'\n" +
                "AND spec = '"+mystring2+"'";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

    //获取班组信息
    @AutoLog(value = "获取工序班组信息")
    @ApiOperation(value="获取工序班组信息", notes="获取工序班组信息")
    @GetMapping(value = "/getbanzu")
    public ResponseEntity<?> getbanzu(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from banzu where bumen='"+mystring+"'";

        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //更新工作中心工艺路线和适用成功品物料
    @AutoLog(value = "更新工作中心工艺路线和适用成功品物料")
    @ApiOperation(value="更新工作中心工艺路线和适用成功品物料", notes="更新工作中心工艺路线和适用成功品物料")
    @PostMapping(value = "/updateworkcenter")
    public ResponseEntity<?> updateworkcenter(
//            @RequestParam(name="luxian", defaultValue="") String luxian,
//            @RequestParam(name="endday", defaultValue="") String endday,
//            @RequestParam(name="tobj", defaultValue="") String tobj,
//            @RequestParam(name="tobj2", defaultValue="") String tobj2,
//            @RequestParam(name="gxmc", defaultValue="") String gxmc,
//            @RequestParam(name="gxmc", defaultValue="") String gdbh
            @RequestBody JSONObject wuliao
    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();
        System.out.println(wuliao);
        String luxian=wuliao.getString("luxian");
        System.out.println(luxian);
        String wuliao1=wuliao.getString("wuliao");
        String fnumber=wuliao.getString("fnumber");




        try {

           String tsql=" update workcenter  set luxian='"+luxian+"',wuliao='"+wuliao1+"' where fnumber='"+fnumber+"'";
           System.out.println(tsql);
           jdbcTemplate.execute(tsql);

            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //完成产线报工
    @AutoLog(value = "完成产线报工")
    @ApiOperation(value="完成产线报工", notes="完成产线报工")
    @PostMapping(value = "/baogong1")
    public ResponseEntity<?> baogong1(
//            @RequestParam(name="startday", defaultValue="") String startday,
//            @RequestParam(name="endday", defaultValue="") String endday,
//            @RequestParam(name="tobj", defaultValue="") String tobj,
//            @RequestParam(name="tobj2", defaultValue="") String tobj2,
//            @RequestParam(name="gxmc", defaultValue="") String gxmc,
//            @RequestParam(name="gxmc", defaultValue="") String gdbh
            @RequestBody JSONObject epara
    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();
        System.out.println(epara);
        String startday=epara.getString("startday");
        System.out.println(startday);
        String endday=epara.getString("endday");
        String tobj=epara.getString("tobj");
        String tobj2=epara.getString("tobj2");
        String gxmc=epara.getString("gxmc");
        String gdbh=epara.getString("gdbh");
        String sql = "";
        System.out.println(tobj);
        JSONArray obj=JSONArray.parseArray(tobj);
        JSONArray obj2=JSONArray.parseArray(tobj2);
        System.out.println(obj);
        System.out.println(obj2);


        try {

            for (int i=0;i<obj.size();i++){
                  //完工数据
                String updatesql="update gxcp set dnum='"+obj.getJSONObject(i).getInteger("dnum")+"',hnum='"+obj.getJSONObject(i).getInteger("hnum")+"' where id='"+obj.getJSONObject(i).getString("id")+"'";

                jdbcTemplate.execute(updatesql);
               //新增合格不过和记录
                String insertsql="insert into jobmat (id,kgtime,wgtime,num,spec,version,wlmc,partcode,fnumber,gxmc) values (uuid(),'"+startday+"','"+endday+"','"+obj.getJSONObject(i).getInteger("dnum")+"','"+obj.getJSONObject(i).getString("spec")+"','"+obj.getJSONObject(i).getString("version")+"','"+obj.getJSONObject(i).getString("partname")+"','"+obj.getJSONObject(i).getString("partcode")+"','"+gdbh+"','"+gxmc+"')";
                System.out.println(insertsql);
                jdbcTemplate.execute(insertsql);
                 insertsql="insert into jobmatqc (id,kgtime,wgtime,num,spec,version,wlmc,partcode,fnumber,gxmc) values (uuid(),'"+startday+"','"+endday+"','"+obj.getJSONObject(i).getInteger("hnum")+"','"+obj.getJSONObject(i).getString("spec")+"','"+obj.getJSONObject(i).getString("version")+"','"+obj.getJSONObject(i).getString("partname")+"','"+obj.getJSONObject(i).getString("partcode")+"','"+gdbh+"','"+gxmc+"')";
                jdbcTemplate.execute(insertsql);

            }
            for (int i=0;i<obj2.size();i++){
                String updatesql="update gxwuliao set lnum='"+obj2.getJSONObject(i).getInteger("lnum")+"'  where id='"+obj2.getJSONObject(i).getString("id")+"'";
                jdbcTemplate.execute(updatesql);
                //领料单
                String insertsql="insert into jobmatlingliao (id,kgtime,wgtime,num,spec,version,wlmc,partcode,fnumber,gxmc) values (uuid(),'"+startday+"','"+endday+"','"+obj2.getJSONObject(i).getInteger("lnum")+"','"+obj2.getJSONObject(i).getString("spec")+"','"+obj2.getJSONObject(i).getString("version")+"','"+obj2.getJSONObject(i).getString("partname")+"','"+obj2.getJSONObject(i).getString("partcode")+"','"+gdbh+"','"+gxmc+"')";

                jdbcTemplate.execute(insertsql);
                //余料单
                int yuliao=obj2.getJSONObject(i).getInteger("num")-obj2.getJSONObject(i).getInteger("lnum");
                insertsql="insert into jobmatyuliao (id,kgtime,wgtime,num,spec,version,wlmc,partcode,fnumber,gxmc) values (uuid(),'"+startday+"','"+endday+"','"+yuliao+"','"+obj2.getJSONObject(i).getString("spec")+"','"+obj2.getJSONObject(i).getString("version")+"','"+obj2.getJSONObject(i).getString("partname")+"','"+obj2.getJSONObject(i).getString("partcode")+"','"+gdbh+"','"+gxmc+"')";

                jdbcTemplate.execute(insertsql);
            }

            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

    //获取所有地区信息
    //订单进度表
    @AutoLog(value = "订单进度表")
    @ApiOperation(value="订单进度表", notes="订单进度表")
    @GetMapping(value = "/orderjindu")
    public ResponseEntity<?> orderjindu(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from\n" +
                "(SELECT\n" +
                "\tf.order_code,\n" +
                "\tf.order_name,\n" +
                "\tf.partcode,\n" +
                "\tf.partname,\n" +
                "\tf.spec,\n" +
                "\tsum(f.num) as num,\n" +
                "\tf.version,\n" +
                "sum(IFNULL(q.dnum,0)) as dnum,\n" +
                "sum(IFNULL(q.hnum,0)) as hnum\n" +
                "\n" +
                "FROM\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\to1.order_code,\n" +
                "\t\t\to1.order_name,\n" +
                "\t\t\to2.partcode,\n" +
                "\t\t\to2.partname,\n" +
                "\t\t\to2.spec,\n" +
                "\t\t\to2.num,\n" +
                "\t\t\to2.version\n" +
                "\t\tFROM\n" +
                "\t\t\torder_maintain o1\n" +
                "\t\tLEFT JOIN orderdetail o2 ON o1.id = o2.sid\n" +
                "\t) f\n" +
                "LEFT JOIN (\n" +
                "\tSELECT\n" +
                "\t\tsum(num) AS sum,\n" +
                "\t\tfnumber,\n" +
                "\t\tordernumber,\n" +
                "\t\tpartcode,\n" +
                "\t\tpartname,\n" +
                "\t\tspec,\n" +
                "\t\tversion\n" +
                "\tFROM\n" +
                "\t\t(\n" +
                "\t\t\tSELECT\n" +
                "\t\t\t\tfnumber,\n" +
                "\t\t\t\tordernumber,\n" +
                "\t\t\t\tpartcode,\n" +
                "\t\t\t\tpartname,\n" +
                "\t\t\t\tspec,\n" +
                "\t\t\t\tversion,\n" +
                "\t\t\t\tnum\n" +
                "\t\t\tFROM\n" +
                "\t\t\t\tmplan m\n" +
                "\t\t\tLEFT JOIN mplandetail m1 ON m.id = m1.mid\n" +
                "\t\t) m\n" +
                "\tGROUP BY\n" +
                "\t\tfnumber,\n" +
                "\t\tordernumber,\n" +
                "\t\tpartcode,\n" +
                "\t\tpartname,\n" +
                "\t\tspec,\n" +
                "\t\tversion\n" +
                ") b ON f.order_code = b.ordernumber\n" +
                "LEFT JOIN (\n" +
                "\tselect sum(dnum) as dnum,sum(hnum) as hnum,plannumber from \n" +
                "(SELECT\n" +
                "\ts.plannumber,\n" +
                "\tIFNULL(s1.dnum, 0) AS dnum,\n" +
                "\tIFNULL(s1.hnum, 0) AS hnum\n" +
                "FROM\n" +
                "\tsporder s\n" +
                "LEFT JOIN gxcp s1 ON s.id = s1.sporderid) e\n" +
                "group by plannumber\n" +
                ") q\n" +
                "on b.fnumber=q.plannumber\n" +
                "group by f.order_code,\n" +
                "\tf.order_name,\n" +
                "\tf.partcode,\n" +
                "\tf.partname,\n" +
                "\tf.spec) k where 1=1";

        try {
            System.out.println(sql);
            if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
                sql+=" and (k.order_code like '%"+mystring+"%' or k.partcode like '%"+mystring+"%')";
            }
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
  //工序领料单查询
  @AutoLog(value = "工序领料单查询")
  @ApiOperation(value="工序领料单查询", notes="工序领料单查询")
  @GetMapping(value = "/getlingliao")
  public ResponseEntity<?> getlingliao(
          @RequestParam(name="mystring", defaultValue="") String mystring

  ){
      JSONObject object1 =  new JSONObject();
      JSONObject object2 =  new JSONObject();

      String sql = "";

      sql = "select * from jobmatlingliao where 1=1";

      try {
          System.out.println(sql);
          if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
              sql+=" and (gxmc like '%"+mystring+"%' or fnumber like '%"+mystring+"%' or partcode like '%"+mystring+"%')";
          }
          List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

          object1.put("data",list);
          object1.put("code", "0000");
          object1.put("msg", "数据获取成功");
          return new ResponseEntity<>(object1, HttpStatus.OK);
      }
      catch (Exception e) {
          e.printStackTrace();
          object1.put("code", "-1");
          object1.put("msg", "系统错误");
          return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


      }
  }
    //工序余下料单查询
    @AutoLog(value = "工序余下料单查询")
    @ApiOperation(value="工序余下料单查询", notes="工序余下料单查询")
    @GetMapping(value = "/getyuliao")
    public ResponseEntity<?> getyuliao(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from jobmatyuliao where 1=1";

        try {
            System.out.println(sql);
            if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
                sql+=" and (gxmc like '%"+mystring+"%' or fnumber like '%"+mystring+"%' or partcode like '%"+mystring+"%')";
            }
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //工序成品库查询
    @AutoLog(value = "工序成品库查询")
    @ApiOperation(value="工序成品库查询", notes="工序成品库查询")
    @GetMapping(value = "/getchengpin")
    public ResponseEntity<?> getchengpin(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from jobmat where 1=1";

        try {
            System.out.println(sql);
            if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
                sql+=" and (gxmc like '%"+mystring+"%' or fnumber like '%"+mystring+"%' or partcode like '%"+mystring+"%')";
            }
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //不合格品查询
    @AutoLog(value = "不合格品查询")
    @ApiOperation(value="不合格品查询", notes="不合格品查询")
    @GetMapping(value = "/getbuhege")
    public ResponseEntity<?> getbuhege(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from jobmatqc where 1=1";

        try {
            System.out.println(sql);
            if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
                sql+=" and (gxmc like '%"+mystring+"%' or fnumber like '%"+mystring+"%' or partcode like '%"+mystring+"%')";
            }
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //计划进度表
    @AutoLog(value = "计划进度表")
    @ApiOperation(value="计划进度表", notes="计划进度表")
    @GetMapping(value = "/getjihua")
    public ResponseEntity<?> getjihua(
            @RequestParam(name="mystring", defaultValue="") String mystring

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from \n" +
                "(SELECT\n" +
                "\tb.fnumber,\n" +
                "\tb.partcode,\n" +
                "\tb.partname,\n" +
                "\tb.spec,\n" +
                "\tb.plannum,\n" +
                "\tIFNULL(w.num, 0) AS num,\n" +
                "\tifnull(w.dnum, 0) AS dnum,\n" +
                "\tIFNULL(w.hnum, 0) AS hnum\n" +
                "FROM\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\tsum(num) AS plannum,\n" +
                "\t\t\tpartcode,\n" +
                "\t\t\tpartname,\n" +
                "\t\t\tspec,\n" +
                "\t\t\tfnumber\n" +
                "\t\tFROM\n" +
                "\t\t\t(\n" +
                "\t\t\t\tSELECT\n" +
                "\t\t\t\t\tfnumber,\n" +
                "\t\t\t\t\tm2.partcode,\n" +
                "\t\t\t\t\tpartname,\n" +
                "\t\t\t\t\tspec,\n" +
                "\t\t\t\t\tm2.num\n" +
                "\t\t\t\tFROM\n" +
                "\t\t\t\t\tmplan m1\n" +
                "\t\t\t\tLEFT JOIN mplandetail m2 ON m1.id = m2.mid\n" +
                "\t\t\t) j\n" +
                "\t\tGROUP BY\n" +
                "\t\t\tj.fnumber,\n" +
                "\t\t\tpartcode\n" +
                "\t) b\n" +
                "LEFT JOIN (\n" +
                "\tSELECT\n" +
                "\t\tsum(dnum) AS dnum,\n" +
                "\t\tsum(hnum) AS hnum,\n" +
                "\t\tsum(num) AS num,\n" +
                "\t\tplannumber,\n" +
                "\t\tpartcode\n" +
                "\tFROM\n" +
                "\t\t(\n" +
                "\t\t\tSELECT\n" +
                "\t\t\t\ts.plannumber,\n" +
                "\t\t\t\tIFNULL(s1.num, 0) AS num,\n" +
                "\t\t\t\tIFNULL(s1.dnum, 0) AS dnum,\n" +
                "\t\t\t\tIFNULL(s1.hnum, 0) AS hnum,\n" +
                "\t\t\t\ts1.partcode,\n" +
                "\t\t\t\ts1.partname,\n" +
                "\t\t\t\ts1.spec\n" +
                "\t\t\tFROM\n" +
                "\t\t\t\tsporder s\n" +
                "\t\t\tLEFT JOIN gxcp s1 ON s.id = s1.sporderid\n" +
                "\t\t) e\n" +
                "\tGROUP BY\n" +
                "\t\tplannumber,\n" +
                "\t\tpartcode\n" +
                ") w ON b.fnumber = w.plannumber) h where 1=1";

        try {
            System.out.println(sql);
            if (mystring == "" || mystring == null || mystring.compareTo("") == 0) {
                sql+=" and ( fnumber like '%"+mystring+"%' or partcode like '%"+mystring+"%')";
            }
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取标准工序
    @AutoLog(value = "获取标准工序")
    @ApiOperation(value="获取标准工序", notes="获取标准工序")
    @GetMapping(value = "/getpro")
    public ResponseEntity<?> getpro(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select * from programm ORDER BY fnumber desc";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);


            object1.put("data",list);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //修改计划开工单状态
    @AutoLog(value = "更新计划开工单状态")
    @ApiOperation(value="更新计划开工单状态", notes="更新计划开工单状态")
    @GetMapping(value = "/updateplanstatus")
    public ResponseEntity<?> updateplanstatus(
            @RequestParam(name="fnumber", defaultValue="") String fnumber

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        try {
            sql="update mplan set status1='已开' where fnumber='"+fnumber+"'";
            System.out.println(sql);
            jdbcTemplate.execute(sql);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

    //获取计划数量

    @AutoLog(value = "获取计划数量")
    @ApiOperation(value="获取计划数量", notes="获取计划数量")
    @GetMapping(value = "/getplansum")
    public ResponseEntity<?> getplansum(
            @RequestParam(name="mystring", defaultValue="") String mystring,
            @RequestParam(name="mystring1", defaultValue="") String mystring1
    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select IFNULL(count(*),0) as jiancedian from jiancedian";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("jiancedian");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //生产实时看板
    @AutoLog(value = "获取总工单数")
    @ApiOperation(value="获取总工单数", notes="获取总工单数")
    @GetMapping(value = "/getgongdansum1")
    public ResponseEntity<?> getgongdansum1(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select IFNULL(count(*),0) as value1 from sporder";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("value1");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "获取完工总工单数")
    @ApiOperation(value="获取完工总工单数", notes="获取完工总工单数")
    @GetMapping(value = "/getwangongsum")
    public ResponseEntity<?> getwangongsum(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "select IFNULL(count(*),0) as value1 from sporder where wgzt='已完工'";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("value1");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //逾期工单数
    @AutoLog(value = "获取逾期工单数")
    @ApiOperation(value="获取逾期工单数", notes="获取逾期工单数")
    @GetMapping(value = "/getyuqi")
    public ResponseEntity<?> getyuqi(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tIFNULL(count(*), 0) AS value1\n" +
                "FROM\n" +
                "\tsporder\n" +
                "WHERE\n" +
                "\twgzt = '未完工'\n" +
                "AND plannumber IN (\n" +
                "\tSELECT\n" +
                "\t\tfnumber\n" +
                "\tFROM\n" +
                "\t\tmplan\n" +
                "\tWHERE\n" +
                "\t\tNOW() >= endday)";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("value1");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "获取完工总工单量")
    @ApiOperation(value="获取完工总工单量", notes="获取完工总工单量")
    @GetMapping(value = "/getgongdansumt")
    public ResponseEntity<?> getgongdansumt(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tsum(gxcp.dnum) AS value1\n" +
                "FROM\n" +
                "\tgxcp\n" +
                "WHERE\n" +
                "\tsporderid IN (\n" +
                "\t\tSELECT\n" +
                "\t\t\tid\n" +
                "\t\tFROM\n" +
                "\t\t\tsporder\n" +
                "\t\tWHERE\n" +
                "\t\t\twgzt = '已完工'\n" +
                "\t)";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("value1");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "获取不合格总量")
    @ApiOperation(value="获取不合格总量", notes="获取不合格总量")
    @GetMapping(value = "/getbuhege1")
    public ResponseEntity<?> getbuhege1(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tsum(gxcp.hnum) AS value1\n" +
                "FROM\n" +
                "\tgxcp\n" +
                "WHERE\n" +
                "\tsporderid IN (\n" +
                "\t\tSELECT\n" +
                "\t\t\tid\n" +
                "\t\tFROM\n" +
                "\t\t\tsporder\n" +
                "\t\tWHERE\n" +
                "\t\t\twgzt = '已完工'\n" +
                "\t)";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("jiancedian",list);
            JSONArray tdata=object2.getJSONArray("jiancedian");
            String jiancedian=tdata.getJSONObject(0).getString("value1");
            object1.put("value",jiancedian);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //
    @AutoLog(value = "日合格率")
    @ApiOperation(value="日合格率", notes="日合格率")
    @GetMapping(value = "/getrihege")
    public ResponseEntity<?> getrihege(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tday1,\n" +
                "\thege / (hege + buhege) * 100 AS hglv\n" +
                "FROM\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\tDATE(j1.wgtime) AS day1,\n" +
                "\t\t\tsum(j1.num) AS hege,\n" +
                "\t\t\tsum(j2.num) AS buhege\n" +
                "\t\tFROM\n" +
                "\t\t\tjobmat j1\n" +
                "\t\tLEFT JOIN jobmatqc j2 ON DATE(j1.wgtime) = DATE(j2.wgtime)\n" +
                "\t\tGROUP BY\n" +
                "\t\t\tj1.wgtime\n" +
                "\t) wt";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            System.out.println(tdata);
            ArrayList<String> categories = new ArrayList<String>();
            ArrayList<Integer> data= new ArrayList<Integer>();
            for (int i=0;i<tdata.size();i++){
                categories.add(tdata.getJSONObject(i).getString("day1"));
                data.add(tdata.getJSONObject(i).getInteger("hglv"));
            }
            JSONArray series=new JSONArray();
            JSONObject object3 =  new JSONObject();
            object3.put("name","日合格率%");
            object3.put("data",data);
            series.add(object3);
            object1.put("categories",categories);
            object1.put("series", series);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "日产量")
    @ApiOperation(value="日产量", notes="日产量")
    @GetMapping(value = "/getrichangliang")
    public ResponseEntity<?> getrichangliang(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tday1,\n" +
                "\thege \n" +
                "FROM\n" +
                "\t(\n" +
                "\t\tSELECT\n" +
                "\t\t\tDATE(j1.wgtime) AS day1,\n" +
                "\t\t\tsum(j1.num) AS hege,\n" +
                "\t\t\tsum(j2.num) AS buhege\n" +
                "\t\tFROM\n" +
                "\t\t\tjobmat j1\n" +
                "\t\tLEFT JOIN jobmatqc j2 ON DATE(j1.wgtime) = DATE(j2.wgtime)\n" +
                "\t\tGROUP BY\n" +
                "\t\t\tj1.wgtime\n" +
                "\t) wt";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            System.out.println(tdata);
            ArrayList<String> categories = new ArrayList<String>();
            ArrayList<Integer> data= new ArrayList<Integer>();
            for (int i=0;i<tdata.size();i++){
                categories.add(tdata.getJSONObject(i).getString("day1"));
                data.add(tdata.getJSONObject(i).getInteger("hege"));
            }
            JSONArray series=new JSONArray();
            JSONObject object3 =  new JSONObject();
            object3.put("name","轧机产量");
            object3.put("data",data);
            series.add(object3);
            object1.put("categories",categories);
            object1.put("series", series);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "完成率")
    @ApiOperation(value="完成率", notes="完成率")
    @GetMapping(value = "/getwanchenglv")
    public ResponseEntity<?> getwanchenglv(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "sum(num) as num\n" +
                "FROM\n" +
                "\tmplandetail";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            double num=tdata.getJSONObject(0).getDouble("num");
            sql="SELECT\n" +
                    "sum(dnum) as num \n" +
                    "from gxcp";
           list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            tdata=object2.getJSONArray("data");
            double num1=tdata.getJSONObject(0).getDouble("num");
            Double bl1=(double) num1/num*100;
            object1.put("label","完成率");
            object1.put("value",bl1);
            object1.put("data",bl1);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "总合格率")
    @ApiOperation(value="总合格率", notes="总合格率")
    @GetMapping(value = "/getzonghegelv")
    public ResponseEntity<?> getzonghegelv(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "sum(dnum) as num \n" +
                "from gxcp";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            double num=tdata.getJSONObject(0).getDouble("num");
            sql="SELECT\n" +
                    "sum(hnum) as num \n" +
                    "from gxcp";
            list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            tdata=object2.getJSONArray("data");
            double num1=tdata.getJSONObject(0).getDouble("num");
            Double bl1=(double) num/(num+num1)*100;
            object1.put("label","总合格率");
            object1.put("value",bl1);
            object1.put("data",bl1);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    @AutoLog(value = "开工率")
    @ApiOperation(value="开工率", notes="开工率")
    @GetMapping(value = "/getkaigonglv")
    public ResponseEntity<?> getkaigonglv(

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "sum(num) as num\n" +
                "FROM\n" +
                "\tmplandetail";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            double num=tdata.getJSONObject(0).getDouble("num");
            sql="SELECT\n" +
                    "sum(dnum) as num \n" +
                    "from gxcp";
            list =  jdbcTemplate.queryForList(sql);
            object2.put("data",list);
            tdata=object2.getJSONArray("data");
            double num1=tdata.getJSONObject(0).getDouble("num");
            Double bl1=(double) num1/num*100;
            object1.put("label","开工率");
            object1.put("value",bl1);
            object1.put("data",bl1);
            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //生产计划MRP与BOM拆解
    @AutoLog(value = "生产计划MRP与BOM拆解")
    @ApiOperation(value="生产计划MRP与BOM拆解", notes="生产计划MRP与BOM拆解")
    @GetMapping(value = "/getmarplist")
    public ResponseEntity<?> getmarplist(
            @ApiParam(value = "planid", required = false) @RequestParam  String planid

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();
        JSONObject object3 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\tm1.id,\n" +
                "\tfnumber,\n" +
                "\tfname,\n" +
                "\tsday,\n" +
                "\tendday,\n" +
                "\twgzt,\n" +
                "\tpartcode,\n" +
                "\tpartname,\n" +
                "\tnum\n" +
                "FROM\n" +
                "\tmplan m1\n" +
                "INNER JOIN mplandetail m2 ON m1.id = m2.mid\n" +
                "WHERE\n" +
                "\tm1.id = '"+planid+"'";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            JSONArray a2=new JSONArray();
            if (tdata.size()>0){
                for (int i=0;i<tdata.size();i++){
                     String partcode=tdata.getJSONObject(i).getString("partcode");
                     //拆解
                    String hsql="select * from pdetail where pid=0  and partcode='"+partcode+"'";
                    List<Map<String, Object>> list1 =  jdbcTemplate.queryForList(hsql);
                    object3.put("data",list1);
                    JSONArray tdata1=object3.getJSONArray("data");
                    String pid=tdata1.getJSONObject(0).getString("id");
                    JSONObject p1=new JSONObject();
                    p1.put("pid",pid);
                    p1.put("partcode",tdata1.getJSONObject(0).getString("partcode"));
                    p1.put("num",tdata1.getJSONObject(0).getString("num"));
                    p1.put("plannum",tdata.getJSONObject(i).getString("num"));
                    a2.add(p1);

                    //拆解顶级物料的所有树形结构以及用量
                    System.out.println(partcode);
                }
            }



            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            object1.put("data", a2);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //获取物料对应的在途量，在制量以及库存量
    @AutoLog(value = "获取物料对应的在途量，在制量以及库存量")
    @ApiOperation(value="获取物料对应的在途量，在制量以及库存量", notes="获取物料对应的在途量，在制量以及库存量")
    @GetMapping(value = "/getmarpjisuan")
    public ResponseEntity<?> getmarpjisuan(
            @ApiParam(value = "partcode", required = false) @RequestParam  String partcode

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();
        JSONObject object3 =  new JSONObject();

        String sql = "";
        String zsum="0";
        String jsum="0";
        String zzsum="0";

        sql = "SELECT\n" +
                "\tsum(num) - sum(ifnull(rnum, 0)) AS zsum,\n" +
                "\tpartcode\n" +
                "FROM\n" +
                "\tcaigouorder s1\n" +
                "LEFT JOIN caigouorderdetail s2 ON s1.id = s2.cid\n" +
                "WHERE\n" +
                "\ts1.isfukuan = '是' and  s2.partcode='"+partcode+"'\n" +
                "GROUP BY\n" +
                "\tpartcode";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            if (tdata.size()>0){
                //在途
                zsum=tdata.getJSONObject(0).getString(zsum);
            }
            String esql="SELECT\n" +
                    "\t*\n" +
                    "FROM\n" +
                    "\t(\n" +
                    "\t\tSELECT\n" +
                    "\t\t\truku.warehouse_name,\n" +
                    "\t\t\truku.partcode,\n" +
                    "\t\t\truku.partname,\n" +
                    "\t\t\tIFNULL(ruku.num, 0) - IFNULL(chuku.num, 0) AS num\n" +
                    "\t\tFROM\n" +
                    "\t\t\t(\n" +
                    "\t\t\t\tSELECT\n" +
                    "\t\t\t\t\tsum(num) AS num,\n" +
                    "\t\t\t\t\tpartcode,\n" +
                    "\t\t\t\t\tpartname,\n" +
                    "\t\t\t\t\twarehouse_name\n" +
                    "\t\t\t\tFROM\n" +
                    "\t\t\t\t\t(\n" +
                    "\t\t\t\t\t\tSELECT\n" +
                    "\t\t\t\t\t\t\tp2.partcode,\n" +
                    "\t\t\t\t\t\t\tp2.num,\n" +
                    "\t\t\t\t\t\t\tp2.partname,\n" +
                    "\t\t\t\t\t\t\tp1.warehouse_name\n" +
                    "\t\t\t\t\t\tFROM\n" +
                    "\t\t\t\t\t\t\tprocurement_warehousing p1\n" +
                    "\t\t\t\t\t\tINNER JOIN procurement_warehousing_child p2 ON p1.id = p2.procurement_warehousing_id\n" +
                    "\t\t\t\t\t) t\n" +
                    "\t\t\t\tGROUP BY\n" +
                    "\t\t\t\t\tpartcode,\n" +
                    "\t\t\t\t\twarehouse_name\n" +
                    "\t\t\t) ruku\n" +
                    "\t\tLEFT JOIN (\n" +
                    "\t\t\tSELECT\n" +
                    "\t\t\t\tsum(num) AS num,\n" +
                    "\t\t\t\tpartcode,\n" +
                    "\t\t\t\tstock\n" +
                    "\t\t\tFROM\n" +
                    "\t\t\t\t(\n" +
                    "\t\t\t\t\tSELECT\n" +
                    "\t\t\t\t\t\tl1.stock,\n" +
                    "\t\t\t\t\t\tl2.partcode,\n" +
                    "\t\t\t\t\t\tl2.partname,\n" +
                    "\t\t\t\t\t\tl2.num\n" +
                    "\t\t\t\t\tFROM\n" +
                    "\t\t\t\t\t\tlingliao l1\n" +
                    "\t\t\t\t\tINNER JOIN lingliaodetail l2 ON l1.id = l2.lid\n" +
                    "\t\t\t\t) e\n" +
                    "\t\t\tGROUP BY\n" +
                    "\t\t\t\tpartcode,\n" +
                    "\t\t\t\tstock\n" +
                    "\t\t) chuku ON ruku.partcode = chuku.partcode\n" +
                    "\t\tAND ruku.warehouse_name = chuku.stock\n" +
                    "\t) j\n" +
                    "WHERE\n" +
                    "\t j.partcode='"+partcode+"'";
            List<Map<String, Object>> list1 =  jdbcTemplate.queryForList(esql);
            object1.put("data",list1);
            JSONArray tdata1=object1.getJSONArray("data");
            if (tdata1.size()>0){
                jsum=tdata1.getJSONObject(0).getString("num");

            }
            String hsql="select sum(num) as num,partcode,partname from \n" +
                    "(select g1.partcode,g1.partname,g1.num from sporder s1 LEFT JOIN gxcp g1\n" +
                    "on s1.id=g1.sporderid  where s1.wgzt='未完工') e1  where partcode='"+partcode+"' group by partcode";
            List<Map<String, Object>> list3 =  jdbcTemplate.queryForList(hsql);
            object3.put("data",list3);
            JSONArray tdata2=object3.getJSONArray("data");
            if (tdata2.size()>0){
                zzsum=tdata2.getJSONObject(0).getString("num");
            }

            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            object1.put("zsum",zsum);
            object1.put("jsum",jsum);
            object1.put("zzsum",zzsum);
            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    //销售订单生成主生产计划
    @AutoLog(value = "销售订单生成主生产计划")
    @ApiOperation(value="销售订单生成主生产计划", notes="销售订单生成主生产计划")
    @GetMapping(value = "/makeplan")
    public ResponseEntity<?> makeplan(
            @ApiParam(value = "id", required = false) @RequestParam  String orderid

    ){
        JSONObject object1 =  new JSONObject();
        JSONObject object2 =  new JSONObject();

        String sql = "";

        sql = "SELECT\n" +
                "\ts1.the_customer,\n" +
                "\ts1.receipt_number,\n" +
                "\ts1.document_date,\n" +
                "\ts2.the_barcode,\n" +
                "\ts2.the_name,\n" +
                "\ts2.specifications,\n" +
                "\ts2.the_model,\n" +
                "\ts2.the_number,\n" +
                "\ts2.id AS entryid\n" +
                "FROM\n" +
                "\tsales_order s1\n" +
                "INNER JOIN the_order_schedule s2 ON s1.id = s2.sales_order_id where s1.id='"+orderid+"'";


        try {
            System.out.println(sql);
            List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

            object2.put("data",list);
            JSONArray tdata=object2.getJSONArray("data");
            String receipt_number="";
            String document_date="";
            String planid="";
            String plannumber="";
            String the_customer="";
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date1 = new Date();
            String currentTime = dateFormat.format(date1);
            if (tdata.size()>0){
                receipt_number=tdata.getJSONObject(0).getString("receipt_number");
                document_date=tdata.getJSONObject(0).getString("document_date");


                //插入主计划

                the_customer=tdata.getJSONObject(0).getString("the_customer");


                System.out.println(tdata);
                for (int i=0;i<tdata.size();i++){
//                    插入明细//
                    Long startTs = System.currentTimeMillis();
                    planid=startTs.toString()+i;
                    String enumber=the_customer;
                    plannumber=receipt_number+planid+i;
                    String tqsql="insert into  mplan (fname,sday,endday,create_by,create_time,id,fnumber,ordernumber) values ('"+enumber+"','"+currentTime+"','"+document_date+"','admin','"+currentTime+"','"+planid+"','"+plannumber+"','"+receipt_number+"')";
                    jdbcTemplate.execute(tqsql);
                    String fsql="insert into mplandetail (mid,partcode,partname,num,id,mingxiid) values  ('"+planid+"','"+tdata.getJSONObject(i).getString("the_barcode")+"','"+tdata.getJSONObject(i).getString("the_name")+"','"+tdata.getJSONObject(i).getString("the_number")+"',uuid(),'"+tdata.getJSONObject(i).getString("entryid")+"')";
                    jdbcTemplate.execute(fsql);
                }
                //更新生产计划
                String dsql="update sales_order set isjihua='是' where id='"+orderid+"'";
                jdbcTemplate.execute(dsql);

            }



            object1.put("code", "0000");
            object1.put("msg", "数据获取成功");
            return new ResponseEntity<>(list, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

   //计划完成
   @AutoLog(value = "计划完成")
   @ApiOperation(value="计划完成", notes="计划完成")
   @GetMapping(value = "/jihuawancheng")
   public ResponseEntity<?> jihuawancheng(

   ){
       JSONObject object1 =  new JSONObject();
       JSONObject object2 =  new JSONObject();

       String sql = "";

       sql = "\n" +
               "SELECT distinct\n" +
               "\ts.fnumber AS type1,\n" +
               "\ts.fname AS type2,\n" +
               "\ts.plannumber AS type3,\n" +
               "\tc.gxmc AS type4,\n" +
               "  s.planname as type5,\n" +

               "  c.partname as type6,\n" +
               "  c.num as type7,\n" +
               "  IFNULL(c.dnum,0) as type8,\n" +
               "  IFNULL(c.hnum,0) as type9\n" +
               "  \n" +
               "FROM\n" +
               "\tsporder s\n" +
               "LEFT JOIN gxcp c ON s.id = c.sporderid";


       try {
           System.out.println(sql);
           List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);

           object2.put("data",list);
           JSONArray tdata=object2.getJSONArray("data");

           object1.put("code", "0000");
           object1.put("msg", "数据获取成功");
           return new ResponseEntity<>(list, HttpStatus.OK);
       }
       catch (Exception e) {
           e.printStackTrace();
           object1.put("code", "-1");
           object1.put("msg", "系统错误");
           return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


       }
   }

    //验证License授权
    @AutoLog(value = "验证License授权")
    @ApiOperation(value="验证License授权", notes="验证License授权")
    @GetMapping(value = "/checklicense")
    public ResponseEntity<?> checklicense(

    ) {
        JSONObject object2 = new JSONObject();
        JSONObject object1 = new JSONObject();
        object2.put("message", "验证成功！");
        try {
            String sql = "select * from ok";

            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            System.out.println(list);

            object1.put("data", list);
            JSONArray a1 = object1.getJSONArray("data");

//			response.setCharacterEncoding("UTF-8");


            if (a1.size() == 0) {

                object2.put("message", "没有license！");

            }
            String miwen = a1.getJSONObject(0).getString("miwen");
            System.out.println(miwen);
            String jieguo = decryptBASE64(miwen);
            System.out.println(jieguo);
            JSONObject mainjson = JSONObject.parseObject(jieguo);
            System.out.println(mainjson);
            String subject1 = mainjson.getString("subject");
            String endtime=mainjson.getString("expiryTime");
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");

            Date date = new Date(System.currentTimeMillis());
            String endtime1=formatter.format(date);
            Date date2= formatter.parse(endtime);
            if (subject.indexOf(subject1)==-1) {

                object2.put("message", "公司名称错误！");

            }
            if (date.after(date2)){
                object2.put("message", "你的系统已经超出使用期限！");
            }
            JSONObject l1=mainjson.getJSONObject("licenseCheck");
            String registerAmount=l1.getString("registerAmount");
            int count1=Integer.parseInt(registerAmount);
            String sql1="select count(*) as count2 from sys_user";
            List<Map<String, Object>> list1 = jdbcTemplate.queryForList(sql1);
            JSONObject j1=new JSONObject();
            j1.put("data",list1);
            JSONArray a3=j1.getJSONArray("data");
            String count2=a3.getJSONObject(0).getString("count2");
            int count3=Integer.parseInt(count2);
            if (count3>count1){
                object2.put("message", "您的并发数超限！");
            }
            return new ResponseEntity<>(object2, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }
    public static String  decryptBASE64(String key) throws Exception {
        // return (new BASE64Decoder()).decodeBuffer(key);
        return new String(Base64.decodeBase64(key));
    }
    public static String getUsername(String token) {
        try {
            DecodedJWT jwt = JWT.decode(token);
            return jwt.getClaim("username").asString();
        } catch (JWTDecodeException e) {
            return null;
        }
    }


    @AutoLog(value = "判断当前用户是否是单点登录")
    @ApiOperation(value="判断当前用户是否是单点登录", notes="判断当前用户是否是单点登录")
    @GetMapping(value = "/dandiandenglu")

    public ResponseEntity<?> dandiandenglu(

            @RequestParam(name="mima", defaultValue="") String mima

    ){
        JSONObject object1 =  new JSONObject();





        try {
            String checkid="1";
//            System.out.println(redisTemplate.hasKey(CommonConstant.PREFIX_USER_TOKEN +mima));

            if (redisTemplate.hasKey(CommonConstant.PREFIX_USER_TOKEN +mima)) {
              checkid="0";
            }
            object1.put("checkid", checkid);

            return new ResponseEntity<>(object1, HttpStatus.OK);
        }
        catch (Exception e) {
            e.printStackTrace();
            object1.put("code", "-1");
            object1.put("msg", "系统错误");
            return new ResponseEntity<>(object1, HttpStatus.BAD_REQUEST);


        }
    }

    @AutoLog(value = "获取规则编码生成")
    @ApiOperation(value="获取规则编码生成", notes="获取规则编码生成")
    @PostMapping(value = "/getRuleCode")
    public ResponseEntity<?> getRuleCode(@RequestBody JSONObject params){
        String prefix = "CN";
        //订单前缀默认为CN 如果规则参数不为空，则取自定义前缀
        if (params != null) {
            Object obj = params.get("prefix");
            if (obj != null) prefix = obj.toString();
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        int random = RandomUtils.nextInt(90) + 10;
        String value = prefix + format.format(new Date()) + random;
        return new ResponseEntity<>(value, HttpStatus.OK);
    }



    @AutoLog(value = "同步盘点记录")
    @ApiOperation(value="同步盘点记录", notes="同步盘点记录")
    @PostMapping(value = "/tongBuPanDian")
    public boolean tongBuPanDian(@RequestParam(value ="data")   String data){
        if(StringUtils.isNotBlank(data)) {
            JSONArray dataList = JSONArray.parseArray(data);
            JSONObject obj = new JSONObject();
            Pandian pandian = new Pandian();
            String mainId = CgformUtil.randomId();
            pandian.setId(mainId);
            pandian.setFangshi("移动盘点");
            pandian.setKeshi("生产科");
            Pandiandetail pandiandetail = new Pandiandetail();
            List<JSONObject> piciList=new ArrayList<>();
            List<JSONObject> activeList=new ArrayList<>();
            JSONObject pobj = new JSONObject();
            String sql="";
            for (int i = 0; i < dataList.size(); i++) {
                pobj = new JSONObject();
                pobj.put("pici",dataList.getJSONObject(i).get("picicode"));
                pobj.put("gongxu",dataList.getJSONObject(i).get("gongxu"));
                if(!piciList.contains(pobj)){
                    piciList.add(pobj);
                    //删除同批次同工序所有移動端记录
                    sql="delete from pandiandetail where picicode='"+pobj.get("pici")+"' and gongxu='"+pobj.get("gongxu")+"' and" +
                            " pid not in (select id from pandian where fangshi='PC端盘点') ";
                    jdbcTemplate.execute(sql);
                }
                if("1".equals(dataList.getJSONObject(i).get("is_active"))&&!activeList.contains(pobj)){
                    activeList.add(pobj);
                }
            }
            for (int i = 0; i < dataList.size(); i++) {
                obj = dataList.getJSONObject(i);
                //插入
                pandiandetail = JSONObject.toJavaObject(obj, Pandiandetail.class);
                pandiandetail.setPid(mainId);
                pandiandetail.setId(CgformUtil.randomId());
                pandiandetailService.save(pandiandetail);
                pandian.setCreateBy(obj.get("create_by").toString());
            }
            pandianService.save(pandian);

            //更新其余批次为失效
            for (JSONObject jobj:activeList) {
                UpdateWrapper<Pandiandetail> wrapper = Wrappers.update();
                wrapper.lambda()
                        .set(Pandiandetail::getIsActive, "0")
                        .eq(Pandiandetail::getGongxu, jobj.getString("gongxu"))
                        .ne(Pandiandetail::getPicicode, jobj.getString("pici"));
                pandiandetailMapper.update(new Pandiandetail(),wrapper);
            }
            return true;
        }
        return false;
    }
}
